package IOperation;


import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Find implements ioperation{

    @Override
    public void work(Booklist booklist) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要查找的图书：>");
        String name = scanner.nextLine();

        int currentNum = booklist.bookCount;
        //遍历数组查找
        int pos = -1;
        for (int i = 0; i < currentNum; i++) {

            //得到当前书的引用
           Book book = booklist.getBooks(i);
           //得到书的名字
           String bookname = book.getBookname();
           //比较
            if(bookname.equals(name)){
                pos = i;//找到
                break;
            }
        }

        if(pos == currentNum) System.out.println("输入的图书不存在......");
        else {
            Book book = booklist.getBooks(pos);
            System.out.println("找到了：" + book);;
        }
    }
}
